﻿//焦点图片轮换
function $(id) { return document.getElementById(id); }

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function () {
            oldonload();
            func();
        }
    }
}

function addBtn() {
    if (!$('focus_turn') || !$('focus_pic') || !$('focus_tx')) return;
    var focusList = $('focus_pic').getElementsByTagName('li');
    if (!focusList || focusList.length == 0) return;
    var btnBox = document.createElement('div');
    btnBox.setAttribute('id', 'focus_btn');
    var SpanBox = '';
    for (var i = 1; i <= focusList.length; i++) {
        var spanList = '<span class="normal">' + i + '</span>';
        SpanBox += spanList;
    }
    btnBox.innerHTML = SpanBox;
    $('focus_turn').appendChild(btnBox);
    $('focus_btn').getElementsByTagName('span')[0].className = 'current';
}

function classNormal() {
    var focusList = $('focus_pic').getElementsByTagName('li');
    var btnList = $('focus_btn').getElementsByTagName('span');
    var txList = $('focus_tx').getElementsByTagName('li');
    for (var i = 0; i < focusList.length; i++) {
        focusList[i].className = 'normal';
        btnList[i].className = 'normal';
        txList[i].className = 'normal';
    }
}

function classCurrent(n) {
    var focusList = $('focus_pic').getElementsByTagName('li');
    var btnList = $('focus_btn').getElementsByTagName('span');
    var txList = $('focus_tx').getElementsByTagName('li');
    focusList[n].className = 'current';
    btnList[n].className = 'current';
    txList[n].className = 'current';
}

var autoKey = false;
function btnTurn() {
    if (!$('focus_turn') || !$('focus_pic') || !$('focus_tx') || !$('focus_btn')) return;
    $('focus_turn').onmouseover = function () { autoKey = true };
    $('focus_turn').onmouseout = function () { autoKey = false };
    var focusList = $('focus_pic').getElementsByTagName('li');
    var btnList = $('focus_btn').getElementsByTagName('span');
    var txList = $('focus_tx').getElementsByTagName('li');
    for (var m = 0; m < btnList.length; m++) {
        btnList[m].onmouseover = function () {
            classNormal();
            this.className = 'current';
            var n = this.childNodes[0].nodeValue - 1;
            focusList[n].className = 'current';
            txList[n].className = 'current';
        }
    }
}

function autoTurn() {
    if (!$('focus_turn') || !$('focus_pic') || !$('focus_tx')) return;
    if (autoKey) return;
    var focusList = $('focus_pic').getElementsByTagName('li');
    var btnList = $('focus_btn').getElementsByTagName('span');
    var txList = $('focus_tx').getElementsByTagName('li');
    for (var i = 0; i < focusList.length; i++) {
        if (focusList[i].className == 'current') {
            var currentNum = i;
        }
    }
    if (currentNum == focusList.length - 1) {
        classNormal();
        classCurrent(0);
    } else {
        classNormal();
        classCurrent(currentNum + 1);
    }

}

addLoadEvent(addBtn);
addLoadEvent(btnTurn);
addLoadEvent(setautoturn);

function setautoturn() {
    setInterval('autoTurn()', 5000);
}

//鐩稿唽鐒︾偣鍥剧墖鍒囨崲
//function imageFocus() {
//    if (!$('image_focus') || !$('image_focus_big') || !$('image_focus_small')) return;
//    var imageSmallLists = $('image_focus_small').getElementsByTagName('li');
//    var imageBigLists = $('image_focus_big').getElementsByTagName('li');
//    for (var i = 0; i < imageSmallLists.length; i++) {
//        imageSmallLists[i].setAttribute('nodeNo', i);
//    }
//    for (var i = 0; i < imageSmallLists.length; i++) {
//        imageSmallLists[i].onmouseover = function () {
//            var n = this.getAttribute('nodeNo');
//            for (var m = 0; m < imageBigLists.length; m++) {
//                imageBigLists[m].className = '';
//            }
//            imageBigLists[n].className = 'current';
//        }
//    }
//}
//addLoadEvent(imageFocus);


function onMOCurrent(name, cur, num) {
    for (var i = 1; i <= num; i++) {
        var obj = document.getElementById(name + i.toString());
        var oUl = document.getElementById("ico" + name + i.toString());
        if (i == cur) {
            obj.className = "current";
            oUl.style.display = "block";
        } else {
            obj.className = "";
            oUl.style.display = "none";
        }
    }
}
